package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Component
// @Aspect
public class MyAspect1 {
    @Pointcut("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public void pt() {
    }

    @Before("pt()")
    public void before() {
        log.info("MyAspect1 before...");
    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("MyAspect1 around before...");

        // 调用目标对象的原始方法执行
        Object result = proceedingJoinPoint.proceed();

        log.info("MyAspect1 around after...");
        return result;
    }

    @After("pt()")
    public void after() {
        log.info("MyAspect1 after...");
    }

    @AfterReturning("pt()")
    public void afterReturning() {
        log.info("MyAspect1 afterReturning...");
    }

    @AfterThrowing("pt()")
    public void afterThrowing() {
        log.info("MyAspect1 afterThrowing...");
    }
}
